
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>引导 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5.3.html" />
    
    
    <link rel="prev" href="5.1.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" >
            
                <a target="_blank" href="https://github.com/xfl03/CoreModTutor">
            
                    
                    源代码仓库（求star）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    目录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="0.html">
            
                <a href="0.html">
            
                    
                    0 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    1 简介
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="1.1.html">
            
                <a href="1.1.html">
            
                    
                    CoreMod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="1.2.html">
            
                <a href="1.2.html">
            
                    
                    Java虚拟机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="1.3.html">
            
                <a href="1.3.html">
            
                    
                    Minecraft混淆方式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    2 Java虚拟机
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    ClassLoader类加载器
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" >
            
                <span>
            
                    
                    ByteCode字节码
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    ASM
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    3 原版 CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="3.1.html">
            
                <a href="3.1.html">
            
                    
                    直接修改class文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="3.2.html">
            
                <a href="3.2.html">
            
                    
                    JavaAgent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="3.3.html">
            
                <a href="3.3.html">
            
                    
                    LaunchWrapper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="3.4.html">
            
                <a href="3.4.html">
            
                    
                    ModLauncher
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    4 FML CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="4.1.html">
            
                <a href="4.1.html">
            
                    
                    1.3.2-1.5.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="4.2.html">
            
                <a href="4.2.html">
            
                    
                    1.6.1-1.12.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="4.3.html">
            
                <a href="4.3.html">
            
                    
                    1.13.2-1.14.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="5.html">
            
                <a href="5.html">
            
                    
                    5 Mixin
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="5.1.html">
            
                <a href="5.1.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8.2" data-path="5.2.html">
            
                <a href="5.2.html">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="5.3.html">
            
                <a href="5.3.html">
            
                    
                    注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="5.4.html">
            
                <a href="5.4.html">
            
                    
                    修改
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="5.5.html">
            
                <a href="5.5.html">
            
                    
                    定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="5.6.html">
            
                <a href="5.6.html">
            
                    
                    融合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="5.7.html">
            
                <a href="5.7.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="5.8.html">
            
                <a href="5.8.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" >
            
                <span>
            
                    
                    附录
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="附录A.html">
            
                <a href="附录A.html">
            
                    
                    附录A 相关工具下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="附录B.html">
            
                <a href="附录B.html">
            
                    
                    附录B 常见Java字节码指令表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="附录C.html">
            
                <a href="附录C.html">
            
                    
                    附录C 参考资料
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >引导</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5F15;&#x5BFC;">&#x5F15;&#x5BFC;</h1>
<p>&#x6709;&#x5173;Mixin&#x5F15;&#x5BFC;&#x90E8;&#x5206;&#x7684;&#x8BF4;&#x660E;&#x53EF;&#x4EE5;&#x53C2;&#x8003; <a href="https://github.com/SpongePowered/Mixin/wiki/Introduction-to-Mixins---The-Mixin-Environment" target="_blank">Introduction to Mixins The Mixin Environment</a>&#x3002;</p>
<p>&#x7531;&#x4E8E;Mixin&#x662F;&#x4E3A;CoreMod&#x670D;&#x52A1;&#x7684;&#xFF0C;&#x6240;&#x4EE5;Mixin&#x9700;&#x8981;&#x4F7F;&#x7528;CoreMod&#x5F15;&#x5BFC;&#x3002;<br>&#x7531;&#x4E8E;LiteLoader&#x548C;Fabric&#x5DF2;&#x7ECF;&#x505A;&#x597D;&#x4E86;&#x5F15;&#x5BFC;&#x5DE5;&#x4F5C;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x9700;&#x8981;&#x7531;&#x6A21;&#x7EC4;&#x624B;&#x52A8;&#x5F15;&#x5BFC;&#x3002;<br>&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;-javaagent&#x53C2;&#x6570;&#x5F15;&#x5BFC;&#xFF08;&#x53C2;&#x89C1;<a href="https://github.com/SpongePowered/Mixin/blob/2c72246fe0b67c145db5510e66c8873df18b5a9f/src/agent/java/org/spongepowered/tools/agent/MixinAgent.java#L208" target="_blank">MixinAgent</a>&#xFF09;&#x3002;</p>
<h2 id="&#x5F15;&#x5BFC;&#x7684;&#x65F6;&#x673A;">&#x5F15;&#x5BFC;&#x7684;&#x65F6;&#x673A;</h2>
<p>&#x501F;&#x7528;Mixin wiki&#x7684;&#x4E00;&#x5F20;&#x56FE;&#x6765;&#x8BF4;&#x660E;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF1A;</p>
<p><img src="https://raw.githubusercontent.com/SpongePowered/Mixin/master/docs/images/mixin_env_2.png" alt=""></p>
<p>&#x56E0;&#x4E3A;Mixin&#x81EA;&#x5E26;&#x4E00;&#x4E2A; <a href="https://github.com/SpongePowered/Mixin/blob/master/src/launchwrapper/java/org/spongepowered/asm/mixin/EnvironmentStateTweaker.java" target="_blank">Tweaker</a> &#x9700;&#x8981;&#x88AB;&#x6DFB;&#x52A0;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x5728;LaunchWrapper&#x8FD8;&#x5728;&#x8C03;&#x7528;&#x5B9E;&#x73B0;<code>ITweaker</code>&#x7684;&#x7C7B;&#x7684;&#x9636;&#x6BB5;&#x5F15;&#x5BFC;Mixin&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x4E0A;&#x56FE;&#x7684;&#x8FC7;&#x7A0B;&#x2460;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x5728;CoreMod&#x5165;&#x53E3;&#x7C7B;&#x5408;&#x9002;&#x7684;&#x65B9;&#x6CD5;&#x4E2D;&#x5F15;&#x5BFC;&#x3002;</p>
<p>&#x518D;&#x56DE;&#x987E;LaunchWarpper&#x7684;<a href="3.3.html">&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;</a>&#xFF0C;&#x56E0;&#x4E3A;Mixin&#x4F1A;&#x5728;<code>TweakClasses</code>&#x4E2D;<a href="https://github.com/SpongePowered/Mixin/blob/2c72246fe0b67c145db5510e66c8873df18b5a9f/src/launchwrapper/java/org/spongepowered/asm/service/mojang/MixinServiceLaunchWrapper.java#L147" target="_blank">&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;Tweaker</a>&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x80FD;&#x5728;&#x5FAA;&#x73AF;<code>tweakClassNames</code>&#x65F6;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x5728;Tweaker&#x7684;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x4E2D;&#xFF09;&#x5F15;&#x5BFC;Mixin&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x629B;&#x51FA;<code>java.util.ConcurrentModificationException</code>&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;Mixin&#x9700;&#x8981;&#x5728;<code>ITweaker</code>&#x4E2D;&#x7684;<code>acceptOptions</code>&#x6216;&#x8005;<code>injectIntoClassLoader</code>&#x4E2D;&#x5F15;&#x5BFC;&#x3002;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x7684;Mixin&#x5F15;&#x5BFC;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> java.io.File;
<span class="hljs-keyword">import</span> java.util.List;
<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.ITweaker;
<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.LaunchClassLoader;
<span class="hljs-keyword">import</span> org.spongepowered.asm.launch.MixinBootstrap;
<span class="hljs-keyword">import</span> org.spongepowered.asm.mixin.Mixins;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExampleTweaker</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ITweaker</span> </span>{
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">injectIntoClassLoader</span><span class="hljs-params">(LaunchClassLoader classLoader)</span> </span>{
        MixinBootstrap.init();
        Mixins.addConfiguration(<span class="hljs-string">&quot;mixins.example.json&quot;</span>); <span class="hljs-comment">// &#x6DFB;&#x52A0;&#x81EA;&#x5DF1;&#x7684;Mixin&#x914D;&#x7F6E;&#x6587;&#x4EF6;</span>
    }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">acceptOptions</span><span class="hljs-params">(List&lt;String&gt; args, File gameDir, File assetsDir, String profile)</span> </span>{ }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getLaunchTarget</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>; }
    <span class="hljs-meta">@Override</span> <span class="hljs-keyword">public</span> String[] getLaunchArguments() { <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> String[<span class="hljs-number">0</span>]; }
}
</code></pre>
<h3 id="tweakclass-or-fmlcoreplugin">TweakClass or FMLCorePlugin?</h3>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#xFF0C;FML&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x5BF9;<code>ITweaker</code>&#x7684;&#x5C01;&#x88C5;&#x63A5;&#x53E3;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;<code>IFMLLoadingPlugin</code>&#xFF0C;&#x4F46;&#x662F;&#xFF0C;<code>MixinBootstrap</code>&#x4E0D;&#x80FD;&#x5728;&#x8FD9;&#x91CC;&#x88AB;<strong>&#x76F4;&#x63A5;&#x8C03;&#x7528;</strong></p>
<h4 id="&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;">&#x4E3A;&#x4EC0;&#x4E48;&#xFF1F;</h4>
<p>&#x56E0;&#x4E3A;<code>IFMLLoadingPlugin</code>&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x662F;&#x901A;&#x8FC7;<code>LaunchClassLoader</code>&#x52A0;&#x8F7D;&#x7684;&#xFF0C;<code>ITweaker</code>&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x662F;&#x901A;&#x8FC7;<code>sun.misc.Launcher$AppClassLoader</code>&#x52A0;&#x8F7D;&#x7684;&#xFF0C;&#x800C;Mixin&#x5F15;&#x5BFC;&#x76F8;&#x5173;&#x7684;&#x7C7B;&#x90FD;&#x4F1A;&#x901A;&#x8FC7;<code>AppClassLoader</code>&#x52A0;&#x8F7D;&#xFF08;&#x53C2;&#x89C1;<a href="https://github.com/SpongePowered/Mixin/blob/2c72246fe0b67c145db5510e66c8873df18b5a9f/src/launchwrapper/java/org/spongepowered/asm/service/mojang/MixinServiceLaunchWrapperBootstrap.java#L53" target="_blank">MixinServiceLaunchWrapperBootstrap</a>&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x5982;&#x679C;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#xFF0C;&#x4F1A;&#x629B;&#x51FA;&#x5982;&#x4E0B;&#x5F02;&#x5E38;&#xFF1A;</p>
<pre><code>java.lang.NoClassDefFoundError: org/spongepowered/asm/service/IMixinService
    at org.spongepowered.asm.service.MixinService.initService(MixinService.java:120)
    at org.spongepowered.asm.service.MixinService.getServiceInstance(MixinService.java:111)
    at org.spongepowered.asm.service.MixinService.getService(MixinService.java:106)
    at org.spongepowered.asm.launch.MixinBootstrap.&lt;clinit&gt;(MixinBootstrap.java:77)
    at com.example.ExamplePlugin.injectData(ExamplePlugin.java:60)
    at net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper.injectIntoClassLoader(CoreModManager.java:151)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:115)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
Caused by: java.lang.ClassNotFoundException: org.spongepowered.asm.service.IMixinService
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:106)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more
</code></pre><h4 id="&#x600E;&#x4E48;&#x529E;&#xFF1F;">&#x600E;&#x4E48;&#x529E;&#xFF1F;</h4>
<p>&#x90A3;&#x5C31;&#x8BA9;<code>IFMLLoadingPlugin</code>&#x5B9E;&#x73B0;&#x7C7B;&#x4E5F;&#x7528;<code>AppClassLoader</code>&#x52A0;&#x8F7D;&#x4E00;&#x6B21;&#x3002;<br><em>&#x4E0D;&#x63A8;&#x8350;&#x8FD9;&#x4E48;&#x505A;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x6837;&#x6253;&#x7834;&#x4E86;FML&#x52A0;&#x8F7D;&#x6A21;&#x7EC4;&#x7684;&#x89C4;&#x5219;</em></p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> java.util.Map;
<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.Launch;
<span class="hljs-keyword">import</span> net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
<span class="hljs-keyword">import</span> org.apache.commons.lang3.reflect.MethodUtils;
<span class="hljs-keyword">import</span> org.spongepowered.asm.launch.MixinBootstrap;
<span class="hljs-keyword">import</span> org.spongepowered.asm.mixin.Mixins;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExamplePlugin</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IFMLLoadingPlugin</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">initMixin</span><span class="hljs-params">()</span> </span>{
        MixinBootstrap.init();
        Mixins.addConfiguration(<span class="hljs-string">&quot;mixins.example.json&quot;</span>);
    }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">injectData</span><span class="hljs-params">(Map&lt;String, Object&gt; data)</span> </span>{
        <span class="hljs-keyword">try</span> {
            ClassLoader appClassLoader = Launch.class.getClassLoader();
            MethodUtils.invokeMethod(appClassLoader, <span class="hljs-keyword">true</span>, <span class="hljs-string">&quot;addURL&quot;</span>, <span class="hljs-keyword">this</span>.getClass().getProtectionDomain().getCodeSource().getLocation());
            MethodUtils.invokeStaticMethod(appClassLoader.loadClass(<span class="hljs-keyword">this</span>.getClass().getName()), <span class="hljs-string">&quot;initMixin&quot;</span>);
        } <span class="hljs-keyword">catch</span> (Exception e) {}
    }
    <span class="hljs-meta">@Override</span> <span class="hljs-keyword">public</span> String[] getASMTransformerClass() { <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>; }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getModContainerClass</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>; }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getSetupClass</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>; }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getAccessTransformerClass</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>; }
}
</code></pre>
<h2 id="&#x5728;tweaker-mod&#x4E2D;&#x4F7F;&#x7528;mod&#x6CE8;&#x89E3;">&#x5728;Tweaker-Mod&#x4E2D;&#x4F7F;&#x7528;<code>@Mod</code>&#x6CE8;&#x89E3;</h2>
<p>&#x5728;FMLCoreMod&#x4E2D;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5728;&#x6E05;&#x5355;&#x6587;&#x4EF6;&#x4E2D;&#x6DFB;&#x52A0;<code>FMLCorePluginContainsFMLMod</code>&#x5C5E;&#x6027;&#x5C31;&#x80FD;&#x8BA9;&#x8FD9;&#x4E2A;&#x6A21;&#x7EC4;&#x4E5F;&#x80FD;&#x4F5C;&#x4E3A;&#x666E;&#x901A;&#x6A21;&#x7EC4;&#x52A0;&#x8F7D;&#xFF0C;&#x4F46;&#x662F;&#x5728;Tweaker-Mod&#x4E2D;&#x662F;&#x4E0D;&#x884C;&#x7684;&#xFF0C;&#x6309;&#x7167;&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;&#xFF0C;FML&#x5728;&#x8BFB;&#x53D6;&#x5230;&#x6709;<code>TweakClass</code>&#x5C5E;&#x6027;&#x540E;&#x5C31;&#x4E0D;&#x518D;&#x7EE7;&#x7EED;&#x8BFB;&#x53D6;&#x5176;&#x4ED6;&#x7684;&#x5C5E;&#x6027;&#x4E86;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x53EA;&#x6709;<code>FMLAT</code>&#x5C5E;&#x6027;&#x4F1A;&#x88AB;&#x8BFB;&#x5230;&#xFF0C;&#x5176;&#x4ED6;&#x90FD;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;&#xFF09;&#x3002;</p>
<p>&#x6309;&#x7167;<a href="https://replaymod.com/" target="_blank">ReplayMod</a>&#x7684;<a href="https://github.com/ReplayMod/ReplayMod/blob/ec50efec104c8345a3a4f20fd44cfb3608cd81bb/src/main/java/com/replaymod/core/LoadingPlugin.java#L26-L42" target="_blank">&#x65B9;&#x6CD5;</a>&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x83B7;&#x53D6;&#x5230;<code>CoreModManager</code>&#x7C7B;&#x4E2D;&#x7684;<code>ignoredModFiles</code>&#x5B57;&#x6BB5;&#xFF0C;&#x5E76;&#x4ECE;&#x4E2D;&#x79FB;&#x9664;&#x6A21;&#x7EC4;&#x81EA;&#x8EAB;&#x6587;&#x4EF6;&#x540D;&#x5373;&#x53EF;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x73B0;&#x5728;&#x5E94;&#x8BE5;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> java.io.File;
<span class="hljs-keyword">import</span> java.net.URISyntaxException;
<span class="hljs-keyword">import</span> java.net.URL;
<span class="hljs-keyword">import</span> java.security.CodeSource;
<span class="hljs-keyword">import</span> java.util.List;
<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.ITweaker;
<span class="hljs-keyword">import</span> net.minecraft.launchwrapper.LaunchClassLoader;
<span class="hljs-keyword">import</span> net.minecraftforge.fml.relauncher.CoreModManager;
<span class="hljs-keyword">import</span> org.apache.logging.log4j.LogManager;
<span class="hljs-keyword">import</span> org.spongepowered.asm.launch.MixinBootstrap;
<span class="hljs-keyword">import</span> org.spongepowered.asm.mixin.Mixins;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExampleTweaker</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ITweaker</span> </span>{
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">injectIntoClassLoader</span><span class="hljs-params">(LaunchClassLoader classLoader)</span> </span>{
        MixinBootstrap.init();
        Mixins.addConfiguration(<span class="hljs-string">&quot;mixins.example.json&quot;</span>);
        CodeSource codeSource = <span class="hljs-keyword">this</span>.getClass().getProtectionDomain().getCodeSource();
        <span class="hljs-keyword">if</span> (codeSource != <span class="hljs-keyword">null</span>) {
            URL location = codeSource.getLocation();
            <span class="hljs-keyword">try</span> {
                File file = <span class="hljs-keyword">new</span> File(location.toURI());
                <span class="hljs-keyword">if</span> (file.isFile()) {
                    CoreModManager.getIgnoredMods().remove(file.getName());
                }
            } <span class="hljs-keyword">catch</span> (URISyntaxException e) {
                e.printStackTrace();
            }
        } <span class="hljs-keyword">else</span> {
            LogManager.getLogger().warn(<span class="hljs-string">&quot;No CodeSource, if this is not a development environment we might run into problems!&quot;</span>);
            LogManager.getLogger().warn(<span class="hljs-keyword">this</span>.getClass().getProtectionDomain());
        }
    }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">acceptOptions</span><span class="hljs-params">(List&lt;String&gt; args, File gameDir, File assetsDir, String profile)</span> </span>{ }
    <span class="hljs-meta">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getLaunchTarget</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>; }
    <span class="hljs-meta">@Override</span> <span class="hljs-keyword">public</span> String[] getLaunchArguments() { <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> String[<span class="hljs-number">0</span>]; }
}
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8BA9;&#x8FD9;&#x4E2A;&#x6A21;&#x7EC4;&#x7684;<code>@Mod</code>&#x6CE8;&#x89E3;&#x4E5F;&#x88AB;&#x8BC6;&#x522B;&#x4E86;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="5.1.html" class="navigation navigation-prev " aria-label="Previous page: 配置">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5.3.html" class="navigation navigation-next " aria-label="Next page: 注入">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"引导","level":"1.8.2","depth":2,"next":{"title":"注入","level":"1.8.3","depth":2,"path":"5.3.md","ref":"5.3.md","articles":[]},"previous":{"title":"配置","level":"1.8.1","depth":2,"path":"5.1.md","ref":"5.1.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"5.2.md","mtime":"2019-09-08T00:42:29.873Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-08T04:47:05.818Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

